packages <- c("CIMseq", "CIMseq.data", "tidyverse")
purrr::walk(packages, library, character.only = TRUE)
rm(packages)

##DATA
load('../data/CIMseqData.rda')
load('../data/sObj.rda')
plotUnsupervisedClass(cObjSng, cObjMul)

plotUnsupervisedMarkers(
  cObjSng, cObjMul,
  c("Lgr5", "Ptprc", "Chga", "Dclk1", "Alpi", "Slc26a3", "Atoh1", "Lyz1"),
  pal = RColorBrewer::brewer.pal(8, "Set1")
)

plotUnsupervisedMarkers(
  cObjSng, cObjMul,
  c("Mki67", "Hoxb13"),
  pal = RColorBrewer::brewer.pal(8, "Set1")
)

cOrder <- as.character(c(
  5, 1, 7, 8, 2, 4, 19, 14, 13, 22, 0,
  16, 18, 23,
  12, 21, 20, 11, 3, 17, 6, 10, 9, 15
))
plotSwarmCircos(sObj, cObjSng, cObjMul, weightCut = 0, classOrder = cOrder)

clockwise
Colon = 5-0 (proximal = 5-8 + 13, distal = 2-14 + 0)
Other 16-23
Small intestine = 12-15

Filtering

Only detected duplicates and triplicates.
Only ERCC estimated cell number < 4.
Weight cutoff = 5.

adj <- adjustFractions(cObjSng, cObjMul, sObj, binary = TRUE)
samples <- rownames(adj)
rs <- rowSums(adj)
keep1 <- rs == 2 
keep2 <- samples %in% filter(estimateCells(cObjSng, cObjMul), estimatedCellNumber <= 4)$sample

plotSwarmCircos(
  filterSwarm(sObj, keep1 & keep2), cObjSng, cObjMul, weightCut = 5, 
  classOrder = cOrder, alpha = 0.01
)